package com.right.handler;

import com.right.command.CsCommand;
import com.right.common.ResponseData;
import com.right.controller.TestController;
import com.right.db.Bicycle;
import com.right.mapper.BicycleMapper;
import com.right.util.SpringUtil;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by ding on 2019/1/16.
 */
@Slf4j
public class InSiteHandler implements PackageHandler{

    private BicycleMapper bicycleMapper;
    @Override
    public boolean applies(List<String> dataList) {
        return CsCommand.IN_SITE.equals(dataList.get(0));
    }

    @Override
    public boolean handleMessage(ChannelHandlerContext ctx, List<String> dataList) {
        log.info("标签进场");
        /*标签*/
        String tag = dataList.get(1);
        //根据标签好查找锁编号
        Example o = new Example(Bicycle.class);
        o.createCriteria().andEqualTo("bicycle_sensors_no",tag);
        o.selectProperties("lock_no");
        Bicycle bicycle = bicycleMapper.selectOneByExample(o);
        String lockNo =null;
        if (bicycle!=null){
             lockNo = bicycle.getLockNo();
        }

        TestController t = SpringUtil.getBean(TestController.class);
        try {
            ResponseData re = t.setAudio(lockNo, "1", "1");

        } catch (InterruptedException e) {
        }
        /*站点编号*/
        String siteNo = dataList.get(2);

        return false;
    }
}
